package com.atguigu.system.controller;

import com.atguigu.model.system.SysLoginLog;
import com.atguigu.model.vo.SysLoginLogQueryVo;
import com.atguigu.system.annotation.Log;
import com.atguigu.system.common.result.Result;

import com.atguigu.system.enums.BusinessType;
import com.atguigu.system.service.SysLoginLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "登录日志管理")
@RestController
@RequestMapping("/admin/system/sysLogLogin")
public class SysLoginLogController {

    @Autowired
    private SysLoginLogService sysLoginLogService;

    @Log(title = "日志管理", businessType = BusinessType.SELECT)
    @PreAuthorize("hasAuthority('bnt.sysLoginLog.list')")
    @ApiOperation(value = "分页展示日志信息")
    @GetMapping("/list/{page}/{limit}")
    public Result showList(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable int page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable int limit,

            @ApiParam(name = "sysLoginLogVo", value = "查询对象", required = false)
            SysLoginLogQueryVo sysLoginLogQueryVo
    ){
            Page<SysLoginLog> pageParam = new Page<>(page,limit);
            IPage<SysLoginLog> pageModel = sysLoginLogService.selectByPage(pageParam, sysLoginLogQueryVo);
            return Result.ok(pageModel);
    }

    @Log(title = "日志管理", businessType = BusinessType.SELECT)
    @PreAuthorize("hasAuthority('bnt.sysLoginLog.list')")
    @ApiOperation(value = "获取日志详情")
    @GetMapping("get/{id}")
    public Result getLog(@PathVariable String id){
        SysLoginLog loginLog = sysLoginLogService.getById(id);
        return Result.ok(loginLog);
    }
}
